home *** CD-ROM | disk | FTP | other *** search
Wrap
/* $VER: BulkMail.thor 2.0 (12.3.97) */ /* Searches the User database for Comments or Aliases */ /* containing the supplied string, and then sends each */ /* match a copy of the currently selected EMail event. */ /* V2.0 adds the option to send a single mail to all */ /* recipients, using either Cc: or Bcc: and a hotlist */ /* of commonly used search strings */ options results /* ;;; Set variables */ EVE_ENTERMSG = 0 /* Event is enter */ EDF_DELETED = '00000001'x /* Event is deleted */ EDF_DONE = '00000004'x /* Event is done */ EDF_FREEZE = '00000020'x /* Event is frozen */ CDF_MAIL = '00000002'x /* Mail conference */ ;;; /* ;;; Get Thor arexx port and load bbsread.library */ thorport = address() if left(thorport,5) ~= 'THOR.' then do say 'FixMail.thor must be run from within Thor.' end if ~show('p', 'BBSREAD') then do address command 'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead' 'WaitForPort BBSREAD' end ;;; /* ;;; Get current system info and selected event number */ address(thorport) 'CURRENTSYSTEM stem CURRENT' System = CURRENT.BBSNAME drop CURRENT. 'GETSELECTEDEVENT' if rc = 5 then call ExitMsg('Event window not open') if rc > 5 then call ExitMsg(THOR.LASTERROR) EventNo = result address(bbsread) drop SYSINFO. 'GETBBSDATA "'System'" SYSINFO' DataPath = SYSINFO.BBSPATH ;;; /* ;;; Get event details */ address(bbsread) 'READBREVENT "'System'" eventnr' EventNo 'datastem EVENTDATA tagsstem EVENTTAGS' if(rc > 0) then call ExitMsg(BBSREAD.LASTERROR) ;;; /* ;;; Make sure it is an EMail event and an Enter event */ drop CONFINFO. 'GETCONFDATA "'System'" "'EVENTTAGS.CONFERENCE'" stem CONFINFO' if bitand(CONFINFO.FLAGS,CDF_MAIL) ~= CDF_MAIL then call ExitMsg('Selected event is not an EMail event') if EVENTDATA.EVENTTYPE ~= EVE_ENTERMSG then call ExitMsg('Selected event is not an Enter event') ;;; /* ;;; Get string to match on */ address(thorport) DefaultStr = '' do while 1 = 1 'REQUESTSTRING TITLE "Search string" BT "_OK|_Address|_Hotlist|_Cancel" BODY "Enter string to search for\nin User Database" ID "'DefaultStr'"' if rc > 5 then call ExitMsg(THOR.LASTERROR) MatchString = result select when THORRC = 1 then leave when THORRC = 2 then DefaultStr = EVENTTAGS.TOADDR when THORRC = 3 then do if ~open(hl,DataPath'BulkMail.hotlist','R') then call ExitMsg('Failed to open hotlist') drop LIST. n = 0 do while ~eof(hl) line = readln(hl) if line = '' then leave n = n + 1 interpret 'LIST.'n' = line' end LIST.COUNT = n call close(hl) 'REQUESTLIST instem LIST outstem tmp title "Select search item"' if rc = 5 then exit if rc > 0 then call ExitMsg(THOR.LASTERROR) DefaultStr = result end otherwise exit end end ;;; /* ;;; Search User Database for matches */ address(thorport) 'REQUESTNOTIFY "Search Alias or Comment fields?" "_Alias|_Comment|_Cancel"' Choice = result select when Choice = 1 then Searchfield = 'ALIAS' when Choice = 2 then Searchfield = 'COMMENT' otherwise exit end address(bbsread) 'SEARCHBRUSER "'System'" STEM SEARCHRESULT SEARCH "#?'MatchString'#?"' SearchField if(rc ~= 0) then call ExitMsg(BBSREAD.LASTERROR) if SearchResult.COUNT = 0 then call ExitMsg('No matches for *"'MatchString'*" found in User database') /* Read names and addresses from user database */ drop Names. Addresses. List. do i = 1 to SearchResult.COUNT UserNo = SearchResult.i.USERNR 'READBRUSER BBSNAME "'System'" USERNR' UserNo 'TAGSSTEM USERTAGS' if rc > 0 then call ExitMsg(BBSREAD.LASTERROR) interpret 'Names.'i' = USERTAGS.NAME' interpret 'Addresses.'i' = USERTAGS.ADDRESS' interpret 'List.'i' = left(USERTAGS.NAME,30)||USERTAGS.ADDRESS' end Names.COUNT = SearchResult.COUNT Addresses.COUNT = SearchResult.COUNT List.COUNT = SearchResult.COUNT ;;; /* ;;; Use all or select? */ address(thorport) 'REQUESTNOTIFY "'SearchResult.COUNT 'matches found" "_All|_Select|_Cancel"' if result = 0 then exit if result = 2 then do /* Select addresses from list */ drop Selected. 'REQUESTLIST instem LIST outstem SELECTED title "Select addresses to send to" MULTISELECT' if rc = 5 then exit if rc > 0 then call ExitMsg(THOR.LASTERROR) /* Copy selected entries to Names. and Addresses. stems */ drop Names. Addresses. do i = 1 to Selected.COUNT interpret 'Names.'i' = strip(left(Selected.'i',30))' interpret 'Addresses.'i' = strip(substr(Selected.'i',31))' end Names.COUNT = Selected.COUNT Addresses.COUNT = Selected.COUNT end ;;; /* ;;; Create separate or copied messages */ address(thorport) 'REQUESTNOTIFY "Send a separate email to each recipient?\nOr one mail with all addresses\nincluded in Cc: or Bcc: headers?" "_Separate|_Cc:|_Bcc:|Cancel"' if rc > 0 then ExitMsg(THOR.LASTERROR) select when result = 0 then exit when result = 1 then do /* Create separate events for each recipient */ address(bbsread) do i = 1 to Names.COUNT interpret 'EVENTTAGS.TONAME = Names.'i interpret 'EVENTTAGS.TOADDR = Addresses.'i 'WRITEBREVENT BBSNAME "'System'" EVENT' EVE_ENTERMSG 'STEM EVENTTAGS' if rc > 0 then call ExitMsg(BBSREAD.LASTERROR) end /* Delete original event? */ address(thorport) 'REQUESTNOTIFY "'i-1 'Email events created\nDelete original event?" "_Yes|_No"' if (result = 1) then do address(bbsread) 'UPDATEBREVENT bbsname "'System'" eventnr' EventNo 'SETDELETED' end end when result = 2 | result = 3 then do /* Add Cc: or Bcc: headers to original event */ if result = 2 then hdr = 'Cc: ' else hdr = 'Bcc: ' /* Build header string, adding line feed when max length is reached */ Header = '' AddressStr = hdr||Addresses.1 do i = 2 to Addresses.COUNT interpret 'NextAddress = Addresses.'i if length(AddressStr','NextAddress) > 250 then do Header = Header||AddressStr||'0a'x AddressStr = hdr end else AddressStr = AddressStr',' AddressStr = AddressStr||NextAddress end if AddressStr > '' then Header = Header||AddressStr||'0a'x /* Write headers to message */ TmpFile = 'T:BulkMail.'time(s) if ~open(out,TmpFile,'W') then ExitMsg('Failed to open temporary file' TmpFile) if ~open(in,DataPath||EVENTTAGS.MSGFILE) then ExitMsg('Failed to open message file') call writech(out,Header) /* Write cc headers */ nextline = readln(in) /* See if message file starts with a custom header */ firstword = word(nextline,1) /* otherwise write a blank line */ if pos(':',firstword) ~= length(firstword) then call writeln(out,'') call writeln(out,nextline) do until eof(in) call writech(out,readch(in,20000)) end call close(out) call close(in) address command 'delete >NIL:' DataPath||EVENTTAGS.MSGFILE 'copy >NIL:' TmpFile DataPath||EVENTTAGS.MSGFILE 'delete >NIL:' TmpFile end otherwise exit end ;;; exit /* ;;; Exit with a message */ ExitMsg: parse arg ErrTxt address(thorport) 'REQUESTNOTIFY "'ErrTxt'" "Abort"' exit ;;;